package socilgirl.dell.mydemo.httpmanager.imhttpinterface;

import android.text.TextUtils;

import socilgirl.dell.mydemo.httpmanager.HttpManagerConstant;
import socilgirl.dell.mydemo.httpmanager.httpinterface.IDowmLoadParameter;


/**
 * Created by ${小强} on 2017/10/27.
 */

public class DownLoadParameter implements IDowmLoadParameter {
    private Builder mBuilder;

    private DownLoadParameter(Builder builder) {
        mBuilder = builder;
    }

    @Override
    public String getDownLoadUrl() {
        if (TextUtils.isEmpty(mBuilder.mDownLoadUrl)) {
            throw new NullPointerException(HttpManagerConstant.URL_NULL);
        }
        return mBuilder.mDownLoadUrl;
    }

    @Override
    public String getFilePath() {
        if (TextUtils.isEmpty(mBuilder.mFilePath)) {
            throw new NullPointerException(HttpManagerConstant.DOWNLOADPATH_NULL);
        }
        return mBuilder.mFilePath;
    }

    @Override
    public String getFlieName() {
        if (TextUtils.isEmpty(mBuilder.mFileName)) {
            throw new NullPointerException(HttpManagerConstant.DOWNLOADNAME_NULL);
        }
        return mBuilder.mFileName;
    }

    public static Builder newBuilder() {

        return new Builder();
    }

    public static class Builder {
        public Builder() {
        }

        private String mDownLoadUrl;
        private String mFileName;
        private String mFilePath;

        /**
         * 添加下载路径
         *
         * @param url
         * @return
         */
        public Builder setDopwnLoadUrl(String url) {
            this.mDownLoadUrl = url;
            return this;
        }

        /**
         * 添加下载文件名字
         *
         * @param fileName
         * @return
         */
        public Builder setFileName(String fileName) {
            this.mFileName = fileName;
            return this;
        }

        /**
         * 添加下载文件路径
         *
         * @param filePath
         * @return
         */
        public Builder setFilePath(String filePath) {
            this.mFilePath = filePath;
            return this;
        }


        public DownLoadParameter build() {
            return new DownLoadParameter(this);
        }
    }
}
